import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import buyCar from './modules/buyCar'

Vue.use(Vuex)

export default new Vuex.Store({
    //data
    state: {
        num: 0,
        msg: "sqa123",
        listData: [],
    },
    //methods
    mutations: {
        addNum(s) {
            s.num++;
        }, setNum(s, v) {
            // this.$store.commit("setNum", val)
            s.num = v;
        }, setList(s, v) {
            s.listData = v
        }
    },
    getters: {
        getMsg(s) {
            return s.msg.split('').reverse().join('')
        }
    },
    //action是提交  mutations的，可以是异步方法
    actions: {
        setList(content) {
            //this.commit("setNum", 111)
            axios.get('http://api-data.vjes.com/apiData.json').then((d) => {
                console.log(d.data)
                content.commit('setList', d.data)
            })
        }
    },
    modules: {
        buyCar
    }
})
